﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace DirInfo
{
    public class Class1
    {
        public static string CreateRootDir(string path,DateTime exmDate)
        {
            string msg = "";
            if (!(Directory.Exists(path)))
            {
                Directory.CreateDirectory(path);
                DirectoryInfo dr = new DirectoryInfo(path);
                dr.CreateSubdirectory(string.Format("{0:dd-MM-yyyy}", exmDate));
                msg = "Directory Created";
            }
            else
            {
                DirectoryInfo dr = new DirectoryInfo(path + @"\" + string.Format("{0:dd-MM-yyyy}", exmDate));
                if (!(dr.Exists))
                {
                    dr.Create();
                    msg = "Directory Created";
                }
                else
                {
                    msg = "Directory Already Exist";
                }
            }
            return msg;
        }
        public static string CreateChildDir(string path, DateTime exmDate, string exmTime)
        {
            string str = "";
            string childdirpath = path + @"\" + string.Format("{0:dd-MM-yyyy}", exmDate) + @"\" + exmTime;
            DirectoryInfo dr = new DirectoryInfo(childdirpath);
            if (!(dr.Exists))
            {
                dr.Create();
                str = "Directory Created";
            }
            else
            {
                str = "Directory All-ready created";
            }
            return str;
        }
        public static string CreateSubChildDir(string path, DateTime exmDate, string exmTime, string exmPaperCode)
        {
            string str = "";
            string childsubdirpath = path + @"\" + string.Format("{0:dd-MM-yyyy}", exmDate) + @"\" + exmTime + @"\" + exmPaperCode;
            DirectoryInfo dr = new DirectoryInfo(childsubdirpath);
            if (!(dr.Exists))
            {
                dr.Create();
                str = "Director Created";
            }
            else
            {
                str = "Directory All-Ready Created";
            }
            return str;
        }
        public static void loadDrive(ComboBox cmb)
        {
            foreach (var drive in DriveInfo.GetDrives())
            {
                cmb.Items.Add(drive);
            }
        }
        public static void loadDir(string p, TreeNode node)
        {
            foreach(var d in Directory.GetDirectories(p))
            {
                TreeNode subdirnode = node.Nodes.Add(Path.GetFileName(d));
                loadDir(d, subdirnode);
                foreach (var f in Directory.GetFiles(d))
                {
                    subdirnode.Nodes.Add(Path.GetFileName(f));
                }
            }
        }
    }
}
